package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List;

import controller.DataUtil;

import entities.Emp;

public class EmpDAO
{
    private Emp emp;

    private List<Emp> list;

    private Connection connection;

    private Statement statement;

    private ResultSet resultSet;

    public List<Emp> findAll()
    {
        DataUtil tt = new DataUtil();
        list = new ArrayList<Emp>();
        connection = MyUtils.getConnection();
        String sql = "select * from emp";

        try
        {
            statement = connection.createStatement();
            resultSet = statement.executeQuery(sql);

            while (resultSet.next())
            {
                emp = new Emp();
                emp.setEmpno(resultSet.getInt(1));
                emp.setEname(resultSet.getString(2));
                emp.setJob(resultSet.getString(3));
                emp.setMgr(resultSet.getInt(4));
                emp.setHiredate(resultSet.getDate(5));
                emp.setSal(resultSet.getFloat(6));
                emp.setComm(resultSet.getFloat(7));
                emp.setDeptno(resultSet.getInt(8));
                list.add(resultSet.getRow() - 1, emp);
            }

            //System.out.println(tt.getNowTime("yyyy-MM-dd") + "�� ��ѯ��ݳɹ�");
        }
        catch (SQLException e)
        {
//            System.out.println(tt.getNowTime("yyyy-MM-dd") + ": ��ѯ���ʧ��");
            e.printStackTrace();
        }
        finally
        {
            MyUtils.free(resultSet, statement, connection);
        }

        return list;
    }

}
